import Zongzi from './Zongzi'
import eat from "@/static/eat.mp3"
let Hand = Hilo.Class.create({
    Extends: Hilo.Container,

    // 图片资源
    img: null,
    img1: null,
    runman1:null,
    runman2:null,
    runman3:null,
    runman4:null,
    runman5:null,
    runman6:null,
    runman7:null,
    soundManager: null,
    pasuestate:false,
    // 碗
    bowl: null,

    // 分数
    score: null,

    constructor: function(properties) {
        Hand.superclass.constructor.call(this, properties);
        this.initHand();
        this.initBowl();

        // this.soundManager = new Hilo.Sound();

        this.soundManager =  new Audio(eat); // 替换为你的声音文件路径
    

    },

    initHand() {
        // 创建手部动画的 Sprite 对象
        let frames = [
            { image: this.runman1, rect: [0, 0, this.runman1.width, this.runman1.height] },
            { image: this.runman2, rect: [0, 0, this.runman2.width, this.runman2.height] },
            { image: this.runman3, rect: [0, 0, this.runman3.width, this.runman3.height] },
            { image: this.runman4, rect: [0, 0, this.runman4.width, this.runman4.height] },
            { image: this.runman5, rect: [0, 0, this.runman5.width, this.runman5.height] },
            { image: this.runman6, rect: [0, 0, this.runman6.width, this.runman6.height] },
            { image: this.runman7, rect: [0, 0, this.runman7.width, this.runman7.height] },
            // 添加更多的帧
        ];

        // 创建 Sprite 对象并添加到容器中
        let handSprite = new Hilo.Sprite({
            id:"hand",
            frames: frames,
            interval: 10, // 每帧间隔时间，单位毫秒
            loop: true // 是否循环播放
        }).addTo(this); // 添加到容器的第一个位置

        handSprite.x = 0; // 设置手部动画的初始位置
        handSprite.y = 0;

        handSprite.play(); // 播放动画
    },

    initBowl() {
        // 初始化碗的 Bitmap 对象
        this.bowl = new Hilo.Bitmap({
            id: 'bowl',
            // 设置碗的位置和大小
            rect: [0, 0, this.img.width / 3, 10],
            x: this.img.width / 3,
            y: 50
        }).addTo(this);
    },

    addScore(image) {
        // 添加分数的 Bitmap 对象
        this.score = new Hilo.Bitmap({
            id: 'score',
            image: image,
            rect: [0, 0, image.width, image.height],
            x: (this.img.width - image.width) / 2,
            y: -image.height
        }).addTo(this);

        // 使用 Tween 动画效果
        Hilo.Tween.to(this.score, {
            x: (this.img.width - image.width / 2) / 2,
            y: -2 * image.height,
            alpha: 0,
            scaleX: 0.5, // 缩小到原来的一半
            scaleY: 0.5
        }, {
            duration: 600,
            ease: Hilo.Ease.Quad.EaseIn,
            onComplete: () => {
                // 动画完成后的回调函数
            }
        });
    },

    // 碰撞检测
    checkCollision(enemy) {
        this.soundManager.play();
        return enemy.hitTestObject(this.bowl, true);
    }
});

export default Hand;
